﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Deployment;
using System.Runtime.InteropServices;
using System.Runtime;
using System.Windows;




namespace Lib_Automation
{


    public class MouseEvent
    {
        [DllImport("user32")]
        static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, uint dwExtraInfo);

        const uint MOUSEEVENTF_ABSOLUTE = 0x8000;
        const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
        const uint MOUSEEVENTF_LEFTUP = 0x0004;
        const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020;
        const uint MOUSEEVENTF_MIDDLEUP = 0x0040;
        const uint MOUSEEVENTF_MOVE = 0x0001;
        const uint MOUSEEVENTF_RIGHTDOWN = 0x0008;
        const uint MOUSEEVENTF_RIGHTUP = 0x0010;
        //const int MOUSEEVENTF_WHEEL = 0x0800;
        const uint MOUSEEVENTF_XDOWN = 0x0080;
        const uint MOUSEEVENTF_XUP = 0x0100;
        const uint MOUSEEVENTF_WHEEL = 0x0800;
        const uint MOUSEEVENTF_HWHEEL = 0x01000;

        public static void MouseClick()
        {
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
        }

        public static void MouseMove(int x, int y)
        {

         int maxX = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
           int maxY = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

           mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, (uint)(x * 65536 / maxX), (uint)(y * 65536 / maxY), 0, 0);
        }

        public static void MouseDown()
        {
            mouse_event(MOUSEEVENTF_LEFTDOWN , 0, 0, 0, 0);
        }

        public static void MouseUp()
        {
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
        }

    }
}
